var app = getApp()
var ImageURL = app.globalData1.ImageURL;
var hostURL = app.globalData1.hostURL;
Page({
   data: {
      statusType: [ "待服务"],
      currentType: 0,
      tabClass: ["", "", "", "", ""],
      orderList: [],
      userId: '',
   },
   statusTap: function (e) {
      var curType = e.currentTarget.dataset.index;
      this.data.currentType = curType
      this.setData({
         currentType: curType
      });
      //this.onLoad();
   },

   onLoad: function (option) {
      var that = this;
      that.setData({
         userId: option.userId,
      });
      // 获取订单列表
      wx.request({
         url: hostURL + 'sharedplatform-web/orderMaster/findOrder.action',
         method: 'post',
         data: {
            userId: that.data.userId,
         },
         header: {
            'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
         },
         success: (res) => {
            //   wx.hideLoading();
            var errno = res.data.errno
            if (errno == 0) {
               console.log("付款订单查询成功")
               //if (res.data.code == 0) {
               that.setData({
                  orderList: res.data.orderListVO,
               });
               //}
               //  console.log(that.data.orderList)
               //  var orderId = that.data.orderList.orderId
               //  console.log(orderId)
            } else if (errno == 1) {
               console.log("改服务不在服务区")
               wx.showToast({
                  title: '您还没有付款订单',
                  content: '',
               })

            } else if (errno == 3) {
               console.log("您还没有付款订单哦亲！")
               wx.showToast({
                  title: '您还没有付款订单',
                  content: '',
               })

            }
         }
      })
   },
   //tofinishTap
   tofinishTap: function (e) {
      var that = this;
      var orderId = e.currentTarget.dataset.id;
      that.setData({
         orderId: orderId
      })
      //console.log(orderId)
      wx.showModal({
         title: '确定完成订单？',
         content: '',
         success: function (res) {
            //   if (res.confirm) {
            wx.showLoading();
            wx.request({
               url: hostURL + 'sharedplatform-web/orderMaster/finishOrder.action',
               data: {
                  orderId: that.data.orderId
               },
               method: 'get',
               header: {
                  'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
               },
               success: (res) => {

                  var errno = res.data.errno
                  if (errno == 0) {
                     console.log("订单完成")
                     wx.showToast({
                        title: '订单完成',
                        content: '',
                     })

                     wx.navigateTo({
                        url: "/pages/shopfinish/shopfinish?userId=" + wx.getStorageSync('userInfo').id
                     });

                  }
                  else if (errno == 1) {
                     wx.showToast({
                        title: '订单为空,订单完成失败',
                        content: '',
                     })
                  }
                  else if (errno == 2) {
                     wx.showToast({
                        title: '订单信息错误,订单完成失败',
                        content: '',
                     })
                  }
               },

            })
            // }
         }
      })
   },
   onReady: function () {
      // 生命周期函数--监听页面初次渲染完成
   },
   onHide: function () {
      // 生命周期函数--监听页面隐藏

   },
   onUnload: function () {
      // 生命周期函数--监听页面卸载

   },
   onPullDownRefresh: function () {
      // 页面相关事件处理函数--监听用户下拉动作

   },
   onReachBottom: function () {
      // 页面上拉触底事件的处理函数

   }
})
